package com.atguigu.spzx.manger.service.impl;

import com.atguigu.spzx.manger.mapper.SysRoleUserMapper;
import com.atguigu.spzx.manger.service.SysRoleUserService;
import com.atguigu.spzx.model.dto.system.AssginRoleDto;
import com.atguigu.spzx.model.entity.system.SysRoleUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRoleUserServiceImpl implements SysRoleUserService {

    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;

    /**
     * 保存分配角色
     *
     * @param assginRoleDto
     */
    @Override
    public void doAssign(AssginRoleDto assginRoleDto) {

        //删除当前用户原来的角色
        sysRoleUserMapper.deleteByUserId(assginRoleDto.getUserId());


        //保存
        List<Long> roleIdList = assginRoleDto.getRoleIdList();
        //遍历
        roleIdList.forEach(roleId -> {

            sysRoleUserMapper.dodoAssign(roleId, assginRoleDto.getUserId());

        });


    }
}
